package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.dubbo.mappers.BlackListMapper;
import com.tanhua.model.domain.BasePojo;
import com.tanhua.model.domain.BlackList;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;


/**
 * @author Xiao
 * @date 2021/10/23
 */
@DubboService
public class BlackListApiImpl implements BlackListApi {
    @Autowired
    private BlackListMapper blackListMapper;

    @Override
    public IPage<BlackList> page(Long userId, Integer page, Integer pagesize) {
        IPage<BlackList> iPage = new Page<>(page, pagesize);
        LambdaQueryWrapper<BlackList> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(BlackList::getUserId, userId);
        wrapper.orderByDesc(BasePojo::getUpdated);
        return blackListMapper.selectPage(iPage, wrapper);
    }

    @Override
    public void removeByUid(Long userId, Long blackUserId) {
        LambdaQueryWrapper<BlackList> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(BlackList::getUserId, userId).eq(BlackList::getBlackUserId, blackUserId);
        blackListMapper.delete(wrapper);
    }
}
